package org.ms.mconf.server.springboot.filter;

import lombok.Setter;
import org.springframework.web.filter.OncePerRequestFilter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

@WebFilter(urlPatterns = "/**")
public class LanguageFilter extends OncePerRequestFilter {

    public static final String LANGUAGE_KEY = "language";

    @Setter
    private Map<String, String> resources;

    @Override
    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
                                    FilterChain filterChain) throws ServletException, IOException {
        Object language = request.getSession().getAttribute(LANGUAGE_KEY);
        if (language == null) {
            request.getSession().setAttribute(LANGUAGE_KEY, resources);
        }
        
        filterChain.doFilter(request, response);
    }

}
